package com.atguigu.srb.core.controller.api;


import com.atguigu.common.results.R;
import com.atguigu.srb.core.pojo.entity.BorrowInfo;
import com.atguigu.srb.core.service.BorrowInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/api/core/borrowInfo")
public class ApiBorrowInfoController {
    @Autowired
    BorrowInfoService borrowInfoService;
    @ApiOperation("查询借款数据审核状态")
    @GetMapping("auth/getStatus")
    public R getStatus( @RequestHeader(value = "token",required = false)
                                    String token){
        Integer status = borrowInfoService.getStatus(token);
        return R.success().data("status",status);
    }

    @ApiOperation("提交借款数据")
    @PostMapping("auth/save")
    public R saveBorrowerInfo(@RequestBody BorrowInfo borrowInfo,
                              //就算请求头中没有token 也希望由我们自己抛出自定义类型的异常
                              //全局异常处理器 就可以根据自定义类型的异常返回失败的R对象 -211
                              @RequestHeader(value = "token",required = false)
                              String token){
        borrowInfoService.saveBorrowerInfo(borrowInfo,token);
        return R.success().message("提交借款数据成功");
    }


}

